CXX = g++

SRCS = tls_server.cc tls_client.cc TLSContext.cc TLSConnection.cc TCPSocket.cc
BUILD_DIR = build
OBJS = $(patsubst %.cc,$(BUILD_DIR)/%.o,$(SRCS))
TARGETS = tls_server tls_client

# INCLUDE_PATH = /home/yoko/jhsec/3rd/tong_suo/include
# LIB_PATH     = /home/yoko/jhsec/3rd/tong_suo/lib64

INCLUDE_PATH = /home/yoko/jhsec/tong_suo_8.3.2/include
LIB_PATH     = /home/yoko/jhsec/tong_suo_8.3.2/lib

CXXFLAGS = -Wall -std=c++17 -I$(INCLUDE_PATH)
LDFLAGS  = -L$(LIB_PATH) -Wl,-rpath=$(LIB_PATH) -lssl -lcrypto

.PHONY: all clean $(BUILD_DIR)

all: $(BUILD_DIR) $(TARGETS)

$(BUILD_DIR):
	mkdir -p $@

tls_server: $(BUILD_DIR)/tls_server.o $(BUILD_DIR)/TLSContext.o $(BUILD_DIR)/TLSConnection.o $(BUILD_DIR)/TCPSocket.o
	$(CXX) $^ -o $@ $(LDFLAGS)

tls_client: $(BUILD_DIR)/tls_client.o $(BUILD_DIR)/TLSContext.o $(BUILD_DIR)/TLSConnection.o $(BUILD_DIR)/TCPSocket.o
	$(CXX) $^ -o $@ $(LDFLAGS)

$(BUILD_DIR)/%.o: %.cc | $(BUILD_DIR)
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -rf $(BUILD_DIR) $(TARGETS)
